package com.ptrsystem.siatd.controllers;

import com.ptrsystem.siatd.beans.EstadoDocSalida;
import com.ptrsystem.siatd.dao.logica.MantenimientoEstDocSalidaLogica;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class EstadoDocSalidaController {

    @Autowired
    private MantenimientoEstDocSalidaLogica logica;

    @RequestMapping(value = "registrarEstDocSalida.htm", method = RequestMethod.GET)
    private String registrarEstDocSalida(HttpServletRequest req) {
        req.getSession(true).setAttribute("codEstDocSal", String.valueOf(logica.generarCodEstDocSalida()));
        req.getSession(true).setAttribute("result", "Estado De Mantenimiento");
        return "Mantenimiento/NRegEstDocSalida";
    }

    @RequestMapping(value = "registraEstDocSalida.htm", method = RequestMethod.POST)
    private String registraEstDocSalida(EstadoDocSalida estDocSal, HttpServletRequest req) {
        estDocSal.setCodEstDocSalida(String.valueOf(logica.generarCodEstDocSalida()));
        boolean rs = logica.registraEstDocSalida(estDocSal);
        if (rs) {
            req.getSession(true).setAttribute("codEstDocSal", String.valueOf(logica.generarCodEstDocSalida()));
            req.getSession(true).setAttribute("result", "Registro Efectado");
        } else {
            req.getSession(true).setAttribute("result", "Registro No Efectuado");
        }

        return "Mantenimiento/NRegEstDocSalida";
    }
}
